#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
template<class T, class S>
ostream& operator << (ostream &o, const pair<T, S> &p) {
return o << '(' << p.first << ", " << p.second << ')';
}
template<template<class, class...> class T, class... A>
typename enable_if<!is_same<T<A...>, string>(), ostream&>::type
operator << (ostream &o, T<A...> V) {
o << '[';
for(auto a : V) o << a << ", ";
return o << ']';
}
typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pl;
typedef vector<ll> vl;
#define G(x) ll x; cin >> x;
#define GD(x) ld x; cin >> x;
#define GS(s) string s; cin >> s;
#define F(i, l, r) for(ll i = l; i < (r); ++i)
#define FD(i, r, l) for(ll i = r; i > (l); --i)
#define P(a, n) { cout << "{ "; F(_, 0, n) cout << a[_] << " "; cout << "}\n"; }
#define EX(x) { cout << x << '\n'; exit(0); }
#define A(a) (a).begin(), (a).end()
#define K first
#define V second
#define M 1000000007 //998244353
#define N 400010
ll ct[2][2 * N], p[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
G(n)
F(i, 1, n + 1) cin >> p[i];
F(k, 0, 2) {
F(i, 1, n + 1) if(p[i] < n) {
ll l = (p[i] + 1 - i + n) % n;
ll r = n - i;
if(r < l) r += n;
ct[k][l]++;
ct[k][r + 1]--;
ct[k][l + n]++;
if(r + 1 + n < 2 * n) ct[k][r + 1 + n]--;
}
F(i, 1, 2 * n) ct[k][i] += ct[k][i - 1];
reverse(p + 1, p + n + 1);
}
ll r0 = 0, r1 = 0; bool rev = false;
cout << ct[0][n] << '\n';
G(q) while(q--) {
G(t)
if(t < 3) {
if((t == 1) == !rev) { G(x) r0 = (r0 - x + n) % n; r1 = (r1 + x) % n; }
else { G(x) r0 = (r0 + x) % n; r1 = (r1 - x + n) % n; }
} else rev = !rev;
cout << ct[rev][n + (rev ? r1 : r0)] << '\n';
}
}
1702D - Not a Cheap String | 1714F - Build a Tree and That Is It |
1703F - Yet Another Problem About Pairs Satisfying an Inequality | 610A - Pasha and Stick |
1200A - Hotelier | 1091A - New Year and the Christmas Ornament |
1352B - Same Parity Summands | 1102A - Integer Sequence Dividing |
630B - Moore's Law | 1004A - Sonya and Hotels |
1680B - Robots | 1690A - Print a Pedestal (Codeforces logo) |
1295A - Display The Number | 1077A - Frog Jumping |
1714G - Path Prefixes | 1369C - RationalLee |
289B - Polo the Penguin and Matrix | 1716A - 2-3 Moves |
1670B - Dorms War | 1716B - Permutation Chain |
987A - Infinity Gauntlet | 1676G - White-Black Balanced Subtrees |
1716D - Chip Move | 1352F - Binary String Reconstruction |
1487B - Cat Cycle | 1679C - Rooks Defenders |
56A - Bar | 1694B - Paranoid String |
35A - Shell Game | 1684A - Digit Minimization |